const mysql=require('mysql2/promise'),
log=console.log,
{con}=require('./common.js');

async function commentLike(id){ 
    const sql = `select state from user.comment where unid=${id};`;
    let state = await con.execute(sql);
    state = state[0][0].state
    if (state=="true"){
        const sql4 = `update  user.comment set comment.like=comment.like-1 where unid=${id};`;
        await con.execute(sql4);
        const sql5 = `update  user.comment set comment.state='' where unid=${id};`;
        await con.execute(sql5);
    }else{
        const sql1 = `update  user.comment set comment.like=comment.like+1 where unid=${id};`;
        await con.execute(sql1);
        const sql2 = `update  user.comment set comment.state='true' where unid=${id};`;
        await con.execute(sql2);
    }
}

module.exports={commentLike}